<?php

/*
 * Copyright 2008 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#namespace tehframework\routing\routes;

#use tehframework\request\Request;
#use tehframework\routing\RouteBase;

class DynamicRoute extends RouteBase
{
	/**
	 * @var string?
	 */
	private $path;
	
	/**
	 * @var string?
	 */
	private $url;
	
	/**
	 * @var Request::METHOD_*?
	 */
	private $method;
	
	/**
	 * @var array
	 */
	private $reqs;
	
	/**
	 * @var array
	 */
	private $defs;
	
	/**
	 * @param  string? $path
	 * @param  string? $url
	 * @param  Request::METHOD_*? $method
	 * @param  array $reqs
	 * @param  array $defs
	 */
	public function __construct(
		$path = null,
		$url = null,
		$method = null,
		array $reqs = array(),
		array $defs = array())
	{
		$this->path   = $path;
		$this->url    = $url;
		$this->method = $method;
		$this->reqs   = $reqs;
		$this->defs   = $defs;
	}
	
	/**
	 * @param  ReflectionMethod $handler
	 * @return StaticRoute
	 */
	public function setHandler(ReflectionMethod $handler)
	{
		$this->defaults['handlerClass']  = $handler->class;
		$this->defaults['handlerMethod'] = $handler->name;
		
		return $this;
	}
	
	/**
	 * @param  array<string,string> $args
	 * @param  array<string,mixed> $opts
	 * @param  Request? $request
	 * @return string
	 */
	protected function doBuild(array $args, array $opts, Request $request = null)
	{
		return $this->path;
	}
	
	/**
	 * @param  Request $request
	 * @param  Response $response
	 * @return Route::RESULT_*
	 */
	protected function doMatch(Request $request, Response $response)
	{
		return self::RESULT_NO_MATCH;
	}
}